Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents LstDVDs As System.Windows.Forms.ListBox Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents TxtDVD As System.Windows.Forms.TextBox Friend WithEvents TxtPrice As System.Windows.Forms.TextBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TxtTax As System.Windows.Forms.TextBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents txtTotal As System.Windows.Forms.TextBox Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents BtnPay As System.Windows.Forms.Button Friend WithEvents BtnClear As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.LstDVDs = New System.Windows.Forms.ListBox Me.Label2 = New System.Windows.Forms.Label Me.GroupBox1 = New System.Windows.Forms.GroupBox Me.BtnQuit = New System.Windows.Forms.Button Me.BtnClear = New System.Windows.Forms.Button Me.BtnPay = New System.Windows.Forms.Button Me.txtTotal = New System.Windows.Forms.TextBox Me.Label6 = New System.Windows.Forms.Label Me.TxtTax = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.TxtPrice = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.TxtDVD = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.Button1 = New System.Windows.Forms.Button Me.Button2 = New System.Windows.Forms.Button Me.GroupBox1.SuspendLayout() Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(220, 28) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(139, 31) Me.Label1.TabIndex = 0 Me.Label1.Text = "DVDs R Us" ' 'LstDVDs ' Me.LstDVDs.Location = New System.Drawing.Point(40, 125) Me.LstDVDs.Name = "LstDVDs" Me.LstDVDs.Size = New System.Drawing.Size(260, 147) Me.LstDVDs.TabIndex = 1 ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(33, 97) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(200, 28) Me.Label2.TabIndex = 2 Me.Label2.Text = "Choose DVD:" ' 'GroupBox1 ' Me.GroupBox1.Controls.Add(Me.Button2) Me.GroupBox1.Controls.Add(Me.BtnQuit) Me.GroupBox1.Controls.Add(Me.BtnClear) Me.GroupBox1.Controls.Add(Me.BtnPay) Me.GroupBox1.Controls.Add(Me.txtTotal) Me.GroupBox1.Controls.Add(Me.Label6) Me.GroupBox1.Controls.Add(Me.TxtTax) Me.GroupBox1.Controls.Add(Me.Label5) Me.GroupBox1.Controls.Add(Me.TxtPrice) Me.GroupBox1.Controls.Add(Me.Label4) Me.GroupBox1.Controls.Add(Me.TxtDVD) Me.GroupBox1.Controls.Add(Me.Label3) Me.GroupBox1.Location = New System.Drawing.Point(347, 97) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(293, 305) Me.GroupBox1.TabIndex = 3 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Purchase Info" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(200, 208) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(80, 35) Me.BtnQuit.TabIndex = 10 Me.BtnQuit.Text = "Quit" ' 'BtnClear ' Me.BtnClear.Location = New System.Drawing.Point(107, 208) Me.BtnClear.Name = "BtnClear" Me.BtnClear.Size = New System.Drawing.Size(80, 35) Me.BtnClear.TabIndex = 9 Me.BtnClear.Text = "Clear" ' 'BtnPay ' Me.BtnPay.Location = New System.Drawing.Point(13, 208) Me.BtnPay.Name = "BtnPay" Me.BtnPay.Size = New System.Drawing.Size(80, 35) Me.BtnPay.TabIndex = 8 Me.BtnPay.Text = "Pay" ' 'txtTotal ' Me.txtTotal.Location = New System.Drawing.Point(113, 153) Me.txtTotal.Name = "txtTotal" Me.txtTotal.ReadOnly = True Me.txtTotal.Size = New System.Drawing.Size(160, 20) Me.txtTotal.TabIndex = 7 Me.txtTotal.Text = "" ' 'Label6 ' Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label6.Location = New System.Drawing.Point(13, 153) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(114, 27) Me.Label6.TabIndex = 6 Me.Label6.Text = "Total:" ' 'TxtTax ' Me.TxtTax.Location = New System.Drawing.Point(113, 111) Me.TxtTax.Name = "TxtTax" Me.TxtTax.ReadOnly = True Me.TxtTax.Size = New System.Drawing.Size(160, 20) Me.TxtTax.TabIndex = 5 Me.TxtTax.Text = "" ' 'Label5 ' Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.Location = New System.Drawing.Point(13, 111) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(114, 28) Me.Label5.TabIndex = 4 Me.Label5.Text = "Tax:" ' 'TxtPrice ' Me.TxtPrice.Location = New System.Drawing.Point(113, 69) Me.TxtPrice.Name = "TxtPrice" Me.TxtPrice.ReadOnly = True Me.TxtPrice.Size = New System.Drawing.Size(160, 20) Me.TxtPrice.TabIndex = 3 Me.TxtPrice.Text = "" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(13, 69) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(114, 28) Me.Label4.TabIndex = 2 Me.Label4.Text = "DVD Price:" ' 'TxtDVD ' Me.TxtDVD.Location = New System.Drawing.Point(113, 35) Me.TxtDVD.Name = "TxtDVD" Me.TxtDVD.ReadOnly = True Me.TxtDVD.Size = New System.Drawing.Size(160, 20) Me.TxtDVD.TabIndex = 1 Me.TxtDVD.Text = "" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(13, 35) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(114, 27) Me.Label3.TabIndex = 0 Me.Label3.Text = "DVD Name:" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(16, 8) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(8, 8) Me.Button1.TabIndex = 4 Me.Button1.Text = "Button1" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(88, 264) Me.Button2.Name = "Button2" Me.Button2.Size = New System.Drawing.Size(144, 32) Me.Button2.TabIndex = 11 Me.Button2.Text = "PayClass" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(644, 465) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.GroupBox1) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.LstDVDs) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "DVDs R Us" Me.GroupBox1.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Dim inpf As IO.StreamReader Dim outf As IO.StreamWriter Const taxRate As Double = 0.07 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim inputLine As String If IO.File.Exists("DVDs.txt") Then inpf = IO.File.OpenText("DVDs.txt") Do Until inpf.Peek() = -1 inputLine = inpf.ReadLine() LstDVDs.Items.Add(inputLine) Loop inpf.Close() Else MsgBox("Please contact technical support - Movie List Not Found") End If End Sub Private Sub LstDVDs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstDVDs.SelectedIndexChanged Dim strLine As String strLine = LstDVDs.SelectedItem strLine = strLine.Trim Dim movie As String Dim price As Double Dim tax As Double Dim total As Double ' find where in line the comma is Dim commapos As Integer = strLine.IndexOf(","c) ' pull out movie title from before comma movie = strLine.Substring(0, commapos) ' pull out price from after comma price = Convert.ToDouble(strLine.Substring(commapos + 1).Trim()) 'MsgBox(movie & " selected - cost is: " & price) TxtDVD.Text = movie TxtPrice.Text = price.ToString("c") tax = price * taxRate TxtTax.Text = tax.ToString("c") total = price + tax txtTotal.Text = total.ToString("c") End Sub Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click TxtDVD.Text = "" TxtPrice.Text = "" TxtTax.Text = "" txtTotal.Text = "" End Sub Private Sub BtnPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPay.Click MsgBox("In real system, this would proceed to form for payment - e.g. handle credit card") ' establish output file outf = IO.File.AppendText("sales.txt") outf.WriteLine(" " & TxtDVD.Text & ", " & TxtPrice.Text & ", " & _ TxtTax.Text & ", " & txtTotal.Text) outf.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim nextDVD As String ' load list box from file If IO.File.Exists("DVDs.txt") Then ' file exists, loop until end of file inpf = IO.File.OpenText("DVDs.txt") Do While inpf.Peek() <> -1 nextDVD = inpf.ReadLine() LstDVDs.Items.Add(nextDVD) Loop inpf.Close() Else MsgBox("Sorry, list of DVDs not found. Please create a file named DVDs.txt in the bin folder") Me.Close() End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try outf = IO.File.AppendText("sales.txt") Catch except As Exception MsgBox("Exception: " & except.Message()) MsgBox("I'm sorry the system is down, you cannot rent a movie right now") End Try Dim outLine As String outLine = "CLASS:" & TxtDVD.Text & ", " & TxtPrice.Text _ & ", " & TxtTax.Text & ", " & txtTotal.Text outf.WriteLine(outLine) outf.Close() End Sub End Class